package com.aaa.service.Impl;

import cn.hutool.core.date.DateUtil;
import com.aaa.entity.Singer;
import com.aaa.mapper.SingerMapper;
import com.aaa.service.SingerService;
import com.aaa.util.SingerPageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class SingerServiceimpl implements SingerService {

    @Resource
    private SingerMapper singerMapper;

    @Override
    public List<Singer> listMySinger() {
        return singerMapper.listMySinger();
    }

    @Override
    public SingerPageInfo<Singer> listAll(Integer pagesize, Integer currentpage, String inputm) {
        //        当前页
        Integer page=(currentpage-1)*pagesize;
        //        尾页
        Integer count = singerMapper.counts(inputm);
        List<Singer> select = singerMapper.listAll(page, pagesize,inputm);
        SingerPageInfo pageInfo=new SingerPageInfo();
        pageInfo.setCountpage(currentpage);
        pageInfo.setWeipage(count);
        pageInfo.setBooks(select);
        return pageInfo;
    }

    @Override
    public Integer save(Singer singer) {
        singer.setSday(DateUtil.today());
        if(singer.getSid()==null){
            Integer insert = singerMapper.insert(singer);
            return insert;
        }else{
            Integer update = singerMapper.update(singer);
            return update;
        }
    }

    @Override
    public Integer delete(Integer sid) {
        return singerMapper.delete(sid);
    }
}
